package mysql

import (
	"gitignore/gitignorerpc/gitignorerpc"
	"gorm.io/gorm"
)

type Collection struct {
	gorm.Model
	User_id        int    `gorm:"type:int;comment:用户ID"`
	Video_id       int    `gorm:"type:int;comment:视频ID"`
	Collect_time   string `gorm:"type:varchar(50);comment:收藏时间"`
	Collect_status string `gorm:"type:varchar(50);comment:收藏状态"`
}

func (e *Collection) FindCollectByAdd(db *gorm.DB) error {
	return db.Debug().Create(e).Error
}

func (e *Collection) FindCollectList(db *gorm.DB, list []*gitignorerpc.CollectionList, in *gitignorerpc.CollectionListRequest) {
	db.Debug().Model(&Collection{}).Scopes(Paginate(int(in.Page), int(in.Size))).
		Joins("LEFT JOIN users ON collections.user_id=users.id").Find(&list)
}

func (e *Collection) FindCollectaByDel(db *gorm.DB, time string) error {
	return db.Debug().Where("time = ?", time).Delete(e).Error
}
